#include <iostream>
#include <vector>
#include <sstream>

int direction[4][2][2] = {{{-1, 0}, {1, 0}},
                          {{0, 1}, {0, -1}},
                          {{1, -1}, {-1, 1}},
                          {{-1, -1}, {1, 1}}};

void dfs(std::vector<std::vector<char>> &mf_map, std::vector<std::vector<bool>> &used,
         int i, int j, int &sz, int d, int &maxv)
{
    if (used[i][j] == true || mf_map[i][j] == 'F')
    {
        maxv = std::max(sz, maxv);
        return;
    }

    int rw = mf_map.size();
    int cl = mf_map[0].size();

    sz += 1;
    used[i][j] = true;

    int y1 = i + direction[d][0][0];
    int x1 = j + direction[d][0][1];
    if (y1 < rw && y1 >= 0 && x1 < cl && x1 >= 0)
        dfs(mf_map, used, y1, x1, sz, d, maxv);

    int y2 = i + direction[d][1][0];
    int x2 = j + direction[d][1][1];
    if (y2 < rw && y2 >= 0 && x2 < cl && x2 >= 0)
        dfs(mf_map, used, y2, x2, sz, d, maxv);
}

int main()
{
    int m, n;
    scanf("%d,%d\n", &m, &n);

    std::vector<std::vector<char>> mf_map(m, std::vector<char>(n));
    for (int i = 0; i < m; i++)
    {
        char c;
        std::string st;
        std::getline(std::cin, st);
        std::istringstream iss(st);
        std::string item;

        for (int j = 0; j < n; j++)
        {
            std::getline(iss, item, ',');
            mf_map[i][j] = item[0];
        }
    }

    // int v_max = 0;
    int maxv = 0;
    for (int d = 0; d < 4; d++)
    {
        std::vector<std::vector<bool>> used(m, std::vector<bool>(n, false));
        for (int i = 0; i < m; i++)
        {
            for (int j = 0; j < n; j++)
            {
                int sz = 0;
                dfs(mf_map, used, i, j, sz, d, maxv);
                // v_max = std::max(v_max, maxv);
            }
        }
    }

    std::cout << maxv << std::endl;
}